#ifndef GAMEDIALOG_H
#define GAMEDIALOG_H
#include <QGraphicsObject>
#include <QEventLoop>
#include <QPropertyAnimation>
#include <QDebug>
#include "gs.h"

using namespace gs;

namespace gs
{
//the black foregound scene when dialog shows
class GameDialogBg : public QGraphicsObject
{
public:
    GameDialogBg(GameDialogManager*);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
};

//normally represents as the dialog background
class GameDialog : public QGraphicsObject
{
    Q_OBJECT
public:
    GameDialog(GameDialogManager*, GameDialogBg*);
    GameDialogManager* getDialogManager(){return _manager;}
    GameTable* getGameTable();
    void moveToBackEnd();
    void moveToFrontEnd();
    void gainTableBlock();
    void releaseTableBlock();
    //normally call in execDialog();
    void startDialog();
    void startDialogNoLock();
    //virtual void execDialog() = 0;
protected:
    GameDialogManager* _manager;
    GameDialogBg* _fore;
    QEventLoop e;
    GameParAnimation* showAnim;
    GameParAnimation* hideAnim;
public slots:
    void hideFinished();
    void hideStarted();
};


class GameMessageBox : public GameDialog
{
    Q_OBJECT

    Q_PROPERTY( int message_index READ getMsgIndex WRITE setMsgIndex RESET resetMsgIndex )
public:
    GameMessageBox(GameDialogManager*, GameDialogBg*);
    int execDialog();
    void setText(QString);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    int  getMsgIndex() { return _msg_index; }
    void resetMsgIndex() { _msg_index = 0; }
    void setMsgIndex( int n ) { _msg_index = n; }

    const static int MSG_INTERVAL = 1;

public slots:
    void updateMessage()
    {
        update();
    }
protected:
    QPixmap _bg;
    QString _msg;
    int     _msg_index;
    QPropertyAnimation * _msg_anim;
};

class GameInfoMessageBox : public GameMessageBox
{
public:
    GameInfoMessageBox(GameDialogManager*, GameDialogBg*);
protected:
    GameDialogButton* okButton;
};
// red yellow blue green black <- standard color order
class GameTaoRequestDialog : public GameMessageBox
{
    Q_OBJECT

public:

    GameTaoRequestDialog(GameDialogManager*, GameDialogBg*);
    GSColor getChosenColor(){return color;}
    GSColor execDialog();
    void chooseColor(GSColor);
protected:
    QList<GameDialogButton*> _taoButtons;
    GSColor color;
public slots:
};

class GameSlotRequestDialog : public GameDialog
{
    Q_OBJECT
public:
    GameSlotRequestDialog(GameDialogManager*, GameDialogBg*);
    GhostSlot* execDialog();
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
    DialogTips* tips;
    GhostSlot* receivedSlot;
protected slots:
    void receiveClickOnSlot(GhostSlot*);
};


class GameTileRequestDialog : public GameDialog
{
    Q_OBJECT
public:
    GameTileRequestDialog(GameDialogManager*, GameDialogBg*);
    VillageTile* execDialog();
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
    DialogTips* tips;
    VillageTile* receivedTile;
protected slots:
    void receiveClickOnTile(VillageTile*);
};

//dice dialog
class GameDiceRequestDialog : public GameDialog
{
    Q_OBJECT
public:
    GameDiceRequestDialog(GameDialogManager*, GameDialogBg*);
    QList<GameDialogDice*> getDiceResult(){return _dices;}
    void execDialog(int);
    void clear();
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    QList<GameDialogDice*> _dices;
protected slots:
    //override
    void hideStarted();
};
//player dialog
class GamePlayerRequestDialog : public GameDialog
{
    Q_OBJECT
public:
    GamePlayerRequestDialog(GameDialogManager*, GameDialogBg*);
    Player* execDialog(bool aLive);
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setPlayerHeads();
protected:
    DialogTips* tips;
    QPixmap _bg;
    Player* _selectedPlayer;
    bool showLive;
    const static int GAP = 5;
protected slots:
    void receivedPlayerHead(GameDialogHeadButton*);
};


}

#endif // GAMEDIALOG_H
